Skip to content

Conversation

johahor
Copy link
Member

@johahor johahor commented Oct 8, 2026

Extends the GraphQL API so the frontend can replace Open Library:

  • searchBooks now returns { books, totalCount } instead of a plain list, so the frontend can show pagination.
  • searchBooks orders by id, so limit/offset pagination is stable (no repeated or skipped books between pages).
  • New book(id) query for the details page. Returns null if the book doesn't exist.

searchBooks now uses Drizzle's SQL builder instead of the query API, so the same filter can be used for both fetching a page and counting all matches with db.$count.

Tested in Apollo Sandbox:

  • searchBooks(title: "harry") gives totalCount 39, matching a direct SQL count.
  • Page 1 (offset 0) and page 2 (offset 5) with limit 5 have no books in common, and ids are ascending.
  • book(id: 1) returns "The Hunger Games", book(id: 999999) returns null.

I'm new to Drizzle and GraphQL, so I used AI (Claude) for explanations and guidance while writing and testing the code, and to review it before committing.

Closes #30

@johahor johahor added the enhancement New feature or request label Oct 8, 2026
@johahor johahor added this to the Deliverable 2 milestone Oct 8, 2026
@johahor johahor requested a review from a team as a code owner October 8, 2026 13:58
@johahor johahor changed the title Feat/search count and book by Feat/search count and book by id Oct 8, 2026
@johahor johahor changed the title Feat/search count and book by id feat: add totalCount, stable ordering and book(id) to GraphQL API Oct 8, 2026
martakam
martakam previously approved these changes Oct 8, 2026
Copy link
Member

@martakam martakam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Left a small comment about code style

Co-authored-by: Martin Alexander Kaminski <martakam@stud.ntnu.no>
@johahor johahor merged commit 744d5ce into main Oct 9, 2026
Sign in to join this conversation on GitHub.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: add sorting, total count and book(id) to the GraphQL API
2 participants